Skip to content

feat(hooks): report where the git-hook floor is and whether it can fail - #498

Merged
sandstream merged 2 commits into
mainfrom
fix/hook-floor-reporting
Aug 20, 2026
Merged

sandstream merged 2 commits into
mainfrom
fix/hook-floor-reporting

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Closes #496. Closes #497.

The root cause was narrower than #496 said

resolveHooksDir() honors core.hooksPath — correct, and src/hooks.ts:8-18 explains why: installing into .git/hooks while git reads elsewhere is a silent no-op. But only the writer used it. Two readers hardcoded <gitDir>/hooks:

  • check-hooks.ts:checkHooks — so kit hooks reported declared hooks as missing while they were installed and firing;
  • commands/hooks.ts's own already-installed pre-check — so every kit hooks add re-reported a fresh installed for a hook that was already there.

Writer and reader disagreeing is the defect. Both now call the same resolver, and a test pins that an installed hook in an external directory is not reported missing.

What the gate now says

New git hook floor row (kit check), ranked by what an operator must do:

state verdict
core.hooksPath points at a directory that does not exist fail (high) — every git hook is OFF, whatever is declared
an installed gate cannot fail (context-check with no [context]) fail (high)
the floor resolves outside the repo warn (medium) — hooks fire, but an unrelated rm -rf removes them
kit hooks wired, inside the repo pass, naming them
no kit-managed hooks here skip — kit does not claim a floor nobody asked for

kit hooks add prints the resolved directory when it is external, instead of a bare ✓ installed.

Detection is deliberately narrow: a hook counts as kit's floor only if it carries the Generated by kit marker and the command it was installed for. A hand-written pre-commit is not claimed, and a repo-relative core.hooksPath (.githooks, the husky case) is correctly not external — both asserted.

The gate that could not fail

kit hooks add context-check with no [context] block installed a pre-push hook that passed every push under a ✓ installed. Now:

$ kit hooks add context-check --non-interactive
✗ refusing to install context-check: no [context] block in .kit.toml.
The hook runs `kit context check`, which has nothing to compare against without one —
it would pass every push and report a gate you do not have.
Run kit context check first: it prints a ready-to-paste [context] block from the live
CLI state. Then re-run this. Or --force to install it now and declare the block after.

The installed hook runs kit context check --require-declaration, so a [context] block that disappears later fails the push instead of passing it. The bare command still exits 0 with the ready-to-paste suggestion — a repo may legitimately have no lock, and a read-only report should not invent one. Only the caller that asked for enforcement gets the strict answer.

Per-hook test hints, too: post-pull-audit and context-check both used to print secret-scan's "stage a fake credential and commit", which exercises nothing for a post-merge or pre-push gate.

Corrected claims

  • fix.ts said git-hook installs "land inside the repo, which the repo-rooted [scope].fs covers". True only while core.hooksPath is unset or repo-relative. The comment now says so and points at the new row; expressing the resolved directory in scopeNeeds needs a dynamic declaration this static one cannot carry, so that stays out of scope rather than being faked.

Tests

src/hook-floor.test.ts — 17, driving temp repos with real core.hooksPath values and the compiled CLI:

  • repo-local floor with kit hooks; a hand-written hook is not claimed; .githooks (repo-relative) is not external; an external dir is; a deleted hooksPath directory means every hook is off
  • context-check unarmed vs armed
  • verdict ordering: dangling > unarmed > external > pass; skip when nothing is installed
  • CLI: the refusal (exit 1, nothing installed), --force, per-hook hints, the external-path warning naming the directory, the git hook floor row in kit check --json, and reader/writer agreement on an external floor

Verification

  • npm test: 4342 tests, 0 fail, 0 skipped (macOS, non-root)
  • kit self-audit: 16 rules, 0 fail, 0 warn
  • prettier --check "src/**/*.ts" clean; flag surface regenerated (--force, --require-declaration) and its drift test green

🤖 Generated with Claude Code

README calls git hooks the agent-agnostic enforcement floor, and nothing
reported on them: kit check had a row for memory hooks and one for the
PreToolUse gates, none for these. Two measured states were invisible.

#496 — the floor can live OUTSIDE the repo. resolveHooksDir() honors
core.hooksPath, which is right (installing into .git/hooks while git reads
elsewhere is a silent no-op), but only the WRITER used it: check-hooks.ts and
`kit hooks add`'s own already-installed pre-check hardcoded <gitDir>/hooks, so
kit installed to one directory and reported on another. Writer and readers now
share the resolver. Measured consequence of the silence: a checkout copied from
another inherits its absolute core.hooksPath, so its hooks live in the other
clone's tree — deleting that unrelated directory let a staged fake credential
commit cleanly, exit 0, with every report green.

#497 — `kit hooks add context-check` installed a gate that could not fail. With
no [context] block there is nothing to compare the live CLI state against, so
the pre-push hook passed every push under a ✓ installed. It now refuses (with
--force for someone about to declare the block), the installed hook runs
`kit context check --require-declaration` so a block that disappears later fails
the push, and each built-in prints how to exercise ITSELF instead of
secret-scan's stage-a-credential recipe.

New `git hook floor` row in the security gate: fail for a gone hooksPath
directory (every hook is off) or an unarmed gate, warn when the floor resolves
outside the repo, pass naming what is wired, skip when the repo has no
kit-managed hooks — kit does not claim a floor nobody asked for.

Also corrects fix.ts's claim that git-hook installs "land inside the repo,
which the repo-rooted [scope].fs covers": true only while core.hooksPath is
unset or repo-relative.

Closes #496
Closes #497

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

…ment flags

CI's Lint step (inside build-and-test) tolerates warnings but not errors, and
these two were errors. `npm run lint` locally reported them too — I had checked
before the file existed.
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit 8514f1c into main Aug 20, 2026
19 checks passed
@sandstream
sandstream deleted the fix/hook-floor-reporting branch August 20, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant